<template>
	<view>
		<userinfo v-if="user_options.toLogin" :options="user_options" @getUserscope="getUserInfo" @toLogin="getUserInfo"></userinfo>
		<view class="container">
			<view v-for="(item,index) in listdata" >
				<view class="container-box" v-if="item.type == 1" >
					<view class="title">{{item.title}}</view>
					<input class="inp-box" type="text"  @input="iptText($event,index)" :value="item.value" placeholder-style="font-size: 28rpx;font-weight: normal;font-stretch: normal;line-height: 50rpx;letter-spacing: 0rpx;color: #c3c3c3;text-align:center"
					 :placeholder="'请输入' + item.title"/>
				</view>
				<view class="container-box" v-if="item.type == 2">
					<view class="title">{{item.title}}</view>
					<view class="">
						<sunuiUpimg :upImgConfig="upImgBasic" @onUpImg="upBasicData($event,index)" @onImgDel="delImgInfo" ref="uImage"></sunuiUpimg>
					</view>
				</view>
			</view>
		</view>
		<view class="btn">
			<button type="primary" :style="btn_style" class="btn-pry" @tap="uPublishTap">提交</button>
		</view>
	</view>
</template>
<script>
	import sunuiUpimg from "../../../appComponent/uni/sunui-upimg/sunui-upimg-basic.vue"
	var common = require('../../../utils/common.js');
	var app = getApp();
	var _this;
	const getCertification = () => {
		common.post('HouseApi&a=authentication_config_list', {
			
		}, data => {
			console.log('++++', data)
			_this.listdata = data.data_list;
			_this.authentication_field = data.authentication_info.authentication_field;
		},_this,fail => {
			uni.showModal({
				title: common.changeTxt('提示'),
				content: fail.data.errorMsg,
				showCancel: false,
				confirmText: common.changeTxt('确定'),
				success: function(res) {
					if (res.confirm) {
						uni.navigateBack()
					}
				}
			});
		});
	};
	// const getconfirmCertification = () => {
	// 	common.post('HouseApi&a=authentication_data ', {
	// 		village_id: _this.village_id,
	// 		pigcms_id: _this.pigcms_id,
	// 		page: 1,
	// 	}, data => {
	// 		console.log('++++', data)
	// 		_this.numlist = data.now_village_bind;
	// 		_this.listdata = data.village_info;
	// 	});
	// };
	export default {
			data() {
				return {
					userInfo:{avatar: '../../../static/images/return-top.png', nickname: '昵称'},
					aricle_title:'',
					basicArr: [],
					authentication_field:{},
					phone:'',
					name:'',
					listdata:[],
					numlist:[],
					imglength: 0,
					imgnum: 8,
					type:0,
					title: '',
					btncolor: '',
					btn_style: '',
					// 基础版配置
					upImgBasic: {
						// 后端图片接口地址
						basicConfig: {
							url: common.requestDomain + 'appapi.php?g=Appapi&c=HouseApi&a=authentication_image'
						},
						// 是否开启提示(提醒上传图片的数量)
						tips: true,
						// 是否开启notli(开启的话就是选择完直接上传，关闭的话当count满足数量时才上传)
						notli: true,
						// 图片数量
						count: 1,
						// 相机来源(相机->camera,相册->album,两者都有->all,默认all)
						sourceType: 'all',
						// 是否压缩上传照片(仅小程序生效)
						sizeType: true,
						// 上传图片背景修改 
						upBgColor: '#E8A400',
						// 上传icon图标颜色修改(仅限于iconfont)
						upIconColor: '#fff',
						// 上传svg图标名称
						// upSvgIconName: 'icon-card',
						// 上传文字描述(仅限四个字)
						// upTextDesc: '上传证书',
						// 删除按钮位置(left,right,bleft,bright),默认右上角
						delBtnLocation: '',
						// 是否隐藏添加图片
						// isAddImage: false,
						// 是否隐藏删除图标
						// isDelIcon: false,
						// 删除图标定义背景颜色
						// delIconColor: '',
						// 删除图标字体颜色
						// delIconText: '',
						// 上传图标替换(+),是个http,https图片地址(https://www.playsort.cn/right.png)
						iconReplace: common.requestDomain + 'static/images/house/upimage.png',
					},  
					cat_id:0,
					village_id:0,
					pigcms_id:0,
					user_options:{},
					page_from:'',
				};
			},
			onShow() {
				// #ifdef H5
					common.hideWxShare()
				// #endif
				
				if (!app.globalData.is_login){
					_this.user_options = {
						toLogin: true
					};
				}
			},
			onLoad: function (options) {
			  _this = this;
			  console.log("报修类型",options.type)
			  _this.type = options.type;
			  _this.title = decodeURIComponent(options.title);
			  
			  if(options.from){
				  _this.page_from = options.from;
			  }
			  
			  common.setMainColor(_this, function(config) {
				_this.btncolor = app.globalData.config.config.mobile_head_color;
				_this.btn_style = 'background-color: ' + _this.btncolor + ';box-shadow:0px 30rpx 30rpx -30rpx ' + _this.btncolor + ';';
			  	
			  });
			  uni.setNavigationBarTitle({
			  	title: "快递员认证"
			  });
			  
			  if(app.globalData.userInfo){
				  _this.userInfo.avatar = app.globalData.userInfo.avatar;
				  _this.userInfo.nickname = app.globalData.userInfo.nickname;
				  console.log('_this.userInfo', _this.userInfo);
			  }
			  
			  var res	= uni.getStorageSync("village_key");
			  _this.village_id = res.village_id;
			  _this.pigcms_id = res.pigcms_id;
			  getCertification();
			  // getconfirmCertification();
			},
			mounted() {
			},
			components: {
				sunuiUpimg,
			},
			methods: {
				iptText(e,index){
					_this.listdata[index].value = e.detail.value;
					console.log("666666666 66",e);
				},
				getLocation_msg(res){
					console.log('反馈信息：', res);
					_this.address = res.name;
				},
				tapChange(e){
					console.log(e.cat_id)
					_this.cat_id = e.cat_id;
				},
				
				uPublishTap() {
					// if(!_this.aricle_title || _this.aricle_title == ''){
					// 	uni.showModal({
					// 		title: common.changeTxt('提示'),
					// 		content: common.changeTxt('您需要输入一些文字才能上报'),
					// 		showCancel: false,
					// 		confirmText: common.changeTxt('好的'),
					// 		success: function(res) {
								
					// 		}
					// 	})
					// 	return false;
					// }
					
					var postData = {
						authentication_field: _this.listdata
					};
					console.log('_this.basicArr.postData', postData);
					
					common.post('HouseApi&a=authentication_data', postData
					, data => {
					  uni.showModal({
					  	title: common.changeTxt('提示'),
					  	content: common.changeTxt('上传成功'),
					  	showCancel: false,
					  	confirmText: common.changeTxt('好的'),
					  	success: function(res) {
					  		if (res.confirm) {
								uni.navigateBack();
					  		}
					  	}
					  });
					});
				},
				// 删除图片 -2019/05/12(本地图片进行删除)
				async delImgInfo(e) {
					console.log('你删除的图片地址为:', e, this.basicArr.splice(e.index, 1));
					_this.imglength = _this.imglength - 1;
					_this.imgnum = _this.imgnum + 1
				},
				// 基础版
				async upBasicData(e,index) {
					console.log('===>',e);
					// 上传图片数组
					let arrImg = [];
					for (let i = 0, len = e.length; i < len; i++) {
						try {
							if (e[i].path_server != "") {
								await arrImg.push(e[i].path_server);
							}
						} catch (err) {
							console.log('上传失败...');
						}
					}
					// 图片信息保存到data数组
					this.basicArr = arrImg;
					_this.listdata[index].value = this.basicArr[0];
					 _this.imglength = this.basicArr.length;
					 _this.imgnum = _this.imgnum - 1;
					// 可以根据长度来判断图片是否上传成功. 2019/4/11新增
					if (arrImg.length == this.upImgBasic.count) {
						uni.showToast({
							title: `上传成功`,
							icon: 'none'
						});
					}
				},
			}
		}
	
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
	.container {
		margin: 0px;
		background: #FFFFFF;
		overflow: hidden;
		padding-bottom: 50rpx;
	}
	.container-box {
		background: #FFFFFF;
		padding: 27rpx;
	}
	.title {
		margin-left: 30rpx;
		font-size: 26rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 50px;
		letter-spacing: 0rpx;
		color: #333333;
	}
	
	.inp-box {
		background: #FFFFFF;
		margin: 0rpx 30rpx;
		padding: 30rpx;
		border-radius: 20rpx;
		border: 2rpx solid #CCCCCC;
	}
	.address {
		margin-left: 0rpx;
		margin-top: 40rpx;
		margin-bottom: 40rpx;
		border:2rpx solid rgba(209,209,209,1);
		border-radius:30rpx;
		display:inline-block;
	}
	.address-text {
		font-size:24rpx;
		font-weight:500;
		color:rgba(204,204,204,1);
		line-height:40rpx;
		padding: 8rpx 20rpx 8rpx 10rpx;
	}
	.address-text:before {
		content: "";
		width:45rpx;
		height:45rpx;
		background: url(../../../static/images/dingwei.png) no-repeat;
		background-size: cover;
		display: block;
		float: left;
	}
	.address-text.has{
		color:black;
	}
	.btn {
		margin: 74rpx 0rpx;
		height: 100%;
		width: 100%;
	}
	.btn-pry {
		width: 550rpx;
		height:98rpx;
		background: #2681f3;
		border-radius:49rpx;
		line-height: 98rpx;
		margin-top: 150rpx;
	}
	.content-class {
		width: 90%;
		margin: 20rpx auto;
		display: flex;
		flex-flow: row wrap;
		justify-content: space-between;
	}
	.tips {
		width: 100%;
		margin-left: 48rpx;
		color: #CCCCCC;
	}
</style>
